'''
身份证格式    1---6 为地址码
7---14 为出生期码    15--17为数字
18为校验码   0--9 或者 x
'''
import requests,re,datetime
from lxml import etree
print('欢迎来到身份证查询中心')
print('-'*80)
try:
    print('温馨提示：身份证为18位，前17位为纯数字哦')
    a = input('请输入你的身份证:')
    print('验证功能')
    a1 = input('请再次输入您的身份证：')
    if a==a1:
        print('两次输入身份证一致')
    else:
        print('两次输入身份证不一致')
    b = a[0:6]
    y1 =int(a[6:10])
    m1=int(a[10:12])
    d1=int(a[12:14])
    d =a[14:18]
except ValueError:
    print('身份证格式错误')
def main():
    url='http://www.mca.gov.cn/article/sj/xzqh/2018/201804-12/20180910291042.html'
    head={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'}
    req=requests.get(url,head)
    html=req.text
    h=etree.HTML(html)
    data=h.xpath('//tr/td[@class="xl7024103"]/text()')
    try:
        dd = datetime.date(year=y1,month=m1,day=d1)
        rr = re.search('\d\d\d(\d|x)', d)
        if b not in data:
            print('身份证前6位出错')
        elif rr == None:
            print('身份证后四位有错误')
        else:
            print('-' * 80)
            print('身份证无问题，666')
    except Exception:
        print('身份证出生年月日错误')
if __name__ == '__main__':
    main()
i='43042120201220032x'
card=r'^([1-9]\d{5}[12]\d{3}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])\d{3}[0-9xX])$'
s=re.search(card,i)
print(s.group())
# import re
# my = input("请输入id_card:\n")
# id_card = r"^([1-9]\d{5}[12]\d{3}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])\d{3}[0-9xX])$"
# hh = re.search(id_card, my)
# print(hh)
